﻿using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Filters;

namespace Nlog_demo
{
    public class CatchExceptionAttribute : Attribute, IExceptionFilter
    {
        public CatchExceptionAttribute()  
        {
        }
        /// <summary>
        /// 发生异常进入
        /// </summary>
        /// <param name="context"></param>
        public async void OnException(ExceptionContext context)
        {
            ContentResult result = new ContentResult
            {
                StatusCode = 500,
                ContentType = "text/json;charset=utf-8;"
            };
            result.Content = "啊哦，出现异常了。";
            context.Result = result;
            context.ExceptionHandled = true;
        }
    }
}



